#pragma once

#include "proxy/common/factory.h"
#include "config.h"


struct Client;
struct Tunnel;

struct Router {

  Router (Client* client, const Config& cfg);

  void startup (Tunnel* tunnel);
  void shutdown ();

  void upLoop ();
  void downLoop ();

  void write (Ptr<IpPackage> pkg);


private:
  const Config& _cfg;
  Client* _client;
  Tunnel* _tunnel;
  s32 _interface;

  std::thread* _upWorker {nullptr};
  std::thread* _downWorker {nullptr};

  BlockQueue<IpPackage, &IpPackage::joint> _queue;
  std::mutex _cache_mutex;
  ByteBuffer<> _cache {IpPackage::MAX_SIZE};
};
